

function SortbySubmit( type ){
	//reset the sort by selector
	var sortby = $( "#sortby" ).val();
	if( sortby == type+"-asc" ){
		$( "#sortby" ).val( type+"-desc" );
	}
	else if( sortby == type+"-desc" ){
		$( "#sortby" ).val( type+"-asc" );
	}
	else{
		$( "#sortby" ).val( type+"-desc" );
	}
	$( "#sortform" ).submit();
}

//for review functions
function LoadSortbyClass(){
	var sortby = $( "#sortby" ).val();

        var id = sortby.substring( 0, sortby.indexOf("-") );
        var sortType = sortby.substring( sortby.indexOf("-")+1, sortby.length );

        $( "#sort"+id ).addClass( "selectedSortby" );
        if( sortType == "asc" ){
            $( "#sort"+id ).append( "<img src=\""+edp_static_domain_url+"image/arrow4.gif\" />" );
        }
        else{
            $( "#sort"+id ).append( "<img src=\""+edp_static_domain_url+"image/arrow5.gif\" />" );
        }
}


$(document).ready(function(){
	
	$("#search_user").click(function()
	{
		window.location.href= edp_domain_url + 'user_search_result/?q='+$("#q").val();
	});

        LoadSortbyClass();

	$( "#sortadd_product_count" ).click(
		function(){
			SortbySubmit( "add_product_count" );
                        return false;
		}
	);
	$( "#sortadd_shop_count" ).click(
		function(){
			SortbySubmit( "add_shop_count" );
                        return false;
		}
	);
	$( "#sortreview_count" ).click(
		function(){
			SortbySubmit( "review_count" );
                        return false;
		}
	);
	$( "#sortcontribution" ).click(
		function(){
			SortbySubmit( "contribution" );
                        return false;
		}
	);

        $( "#sortflower_count" ).click(
		function(){
			SortbySubmit( "flower_count" );
                        return false;
		}
	);
});    

function addFriendInit(){
        //add friend
        $("a[class='add_friend']").click(function()
        {
                var friendID=$(this).attr("name").split("_")[0];
                var friendName=$(this).attr("name").split("_")[1];

                $.ajax(
                {
                        type: 'get',
                        url: edp_domain_url + 'ajax_log_info/?tiny=1',
                        timeout: 5000,
                        global:false,
                        beforeSend: function()
                        {
                                $.blockUI(
                                {
                                        message: '验证用户...',
                                        css: { padding:'5px',color:'#CC0000'}
                                });
                        },
                        error: function()
                        {
                                $.blockUI(
                                {
                                        message: '验证出错...',
                                        css: { padding:'5px',color:'#CC0000'}
                                });
                                $.unblockUI();
                        },
		success: function(data)
                    {
                                if(data==false)
                                {
                                        popupLogin($('#PopBox'),'添加好友');
                                }
                                else
                                {
                                        popupAddFriend($('#PopBox'),friendID,friendName);
                                }
                                $.blockUI(
                                {
                                        message: $('#PopBox'),
                                        css:
                                        {
                                                padding:        0,
                                                margin:         0,
                                                top:            '30%',
                                        left:           '35%',
                                                width:          '',
                                                textAlign:      '',
                                                color:          '',
                                                border:         '',
                                                backgroundColor:'',
                                                cursor:         'wait'
                                         }
                                });
                        }
                });
        });
}

$(document).ready(function(){

		addFriendInit();
	//Function to refresh the validate image
	$("#virefresh").click(function()
	{ 
		$("#vimg").attr('src', edp_domain_url + 'vcode/?tiny='+Math.random());
	});
});

